package com.wyb.dao.impl;

import com.wyb.dao.UserDao;
import com.wyb.entity.User;
import com.wyb.util.JDBCUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class UserDaoImpl implements UserDao {
    JdbcTemplate template= JDBCUtils.getTemplate();
    @Override
    public User selectUserByName(String name) {
       String sql="select * from t_user where user_name=?";
         List<User> list=template.query(sql,new BeanPropertyRowMapper<>(User.class),name);
       return list.isEmpty()?null:list.get(0);
    }

    @Override
    public int insertUser(User user) {
        String sql="insert into t_user(user_name,password,mobile,sex,age,description) values(?,?,?,?,?,?)";
        return template.update(sql,user.getUserName(),user.getPassword(),user.getMobile(),user.getSex(),user.getAge(),user.getDescription());
    }
}
